package com.seezoon.application.device.executor;

import com.seezoon.application.device.dto.UpdateFenceCmd;
import com.seezoon.domain.service.device.DeviceFenceService;
import com.seezoon.domain.service.device.vo.FenceVO;
import com.seezoon.infrastructure.configuration.context.SecurityContextHolder;
import com.seezoon.infrastructure.dto.Response;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 更新围栏执行器
 */
@RequiredArgsConstructor
@Slf4j
@Component
@Validated
public class UpdateFenceCmdExe {

    private final DeviceFenceService deviceFenceService;

    public Response execute(@Valid @NotNull UpdateFenceCmd cmd) {
        Long uid = SecurityContextHolder.get().getUid();
        FenceVO fenceVO = new FenceVO();
        fenceVO.setId(cmd.getId());
        fenceVO.setUid(uid);
        fenceVO.setFenceName(cmd.getFenceName());
        fenceVO.setCenterLatitude(cmd.getCenterLatitude());
        fenceVO.setCenterLongitude(cmd.getCenterLongitude());
        fenceVO.setRadius(cmd.getRadius());
        fenceVO.setStatus(cmd.getStatus());
        deviceFenceService.updateFence(fenceVO);
        return Response.success();
    }
} 